import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
// 引入elementUI
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import './plugins/element.js'
// 引入全局样式
import './assets/css/global.css'
// 引入字体图标
import 'font-awesome/css/font-awesome.min.css'
// 进度条
import Nprogress from 'nprogress'
import 'nprogress/nprogress.css'
import axios from 'axios'
axios.defaults.headers.post['Content-Type'] = 'application/json'
// 配置请求的根路径
axios.defaults.baseURL = '/api'
// 设置请求拦截器
axios.interceptors.request.use(config => {
  Nprogress.start()
  // console.log(config)
  config.headers.Authorization = window.sessionStorage.getItem('token')
  return config
})
// 设置响应拦截器
axios.interceptors.response.use(
  config => {
    Nprogress.done()
    // console.log(config)
    if (config.data.data === 102) {
      // this.$message.error('登陆过期请重新登陆')
      sessionStorage.clear()
      router.push('/login')
    }
    return config
  },
  error => {
    console.log(error)
    // eslint-disable-next-line eqeqeq
  }
)
Vue.prototype.$http = axios
Vue.use(ElementUI)

Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
